package com.tencent.sr.iris.activity.service.event.task;

import com.tencent.sr.iris.activity.dependency.user.UserCoreDependency;
import com.tencent.sr.iris.activity.domain.event.dto.ActivityDTO;
import com.tencent.sr.iris.activity.domain.event.dto.ActivityTaskDTO;
import com.tencent.sr.iris.activity.interfaces.event.dto.ActivityEventDTO;
import com.tencent.sr.iris.activity.service.activity.ActivityCommonService;
import com.tencent.sr.iris.activity.service.event.util.ActivityCommonUtilService;
import com.tencent.sr.rmall.common.exception.retail.TRetailBizException;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SpecialInviteCommissionTaskExecutor extends IrisInviteCommissionTaskExecutor {

    @Resource
    private UserCoreDependency userCoreDependency;

    @Resource
    private ActivityCommonService activityCommonService;

    @Resource
    private ActivityCommonUtilService activityCommonUtilService;

    /**
     * 重写
     * 特邀邀请有礼活动,以成为见习会员时间做任务时间准入的校验
     *
     * @param eventDTO
     * @param act
     * @param task
     */
    @Override
    void before(ActivityEventDTO eventDTO, ActivityDTO act, ActivityTaskDTO task) {

        //查询成为见习时间
        Long becomeTraineeTime = activityCommonService.queryTraineeTime(eventDTO.getUid());
        if (becomeTraineeTime < task.getStartTime().getTime() || becomeTraineeTime > task.getEndTime().getTime()) {
            log.info("任务处理：用户成为见习会员时间不在任务时间范围内,不处理，eventIdempotent:{},traineeTime:{},taskId:{},taskTime:{}-{}",
                    eventDTO.getIdempotent(), becomeTraineeTime, task.getBizId(), task.getStartTime(),
                    task.getEndTime());
            throw new TRetailBizException("见习会员时间不在任务时间范围内，不处理");
        }

    }

}

